package com.jwinni.IO.ObjectStream;

import com.jwinni.IO.entity.person;

import java.io.*;
import java.util.ArrayList;

public class DemoObject {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("static/person.txt"));
        ArrayList<person> arrayList= new ArrayList<>();
        arrayList.add(new person("付宇佳",25));
        arrayList.add(new person("张婉妮",24));
        oos.writeObject(arrayList);
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("static/person.txt"));

        Object o = ois.readObject();
        ArrayList<person> o1 = (ArrayList<person>) o;
        for (person p:o1) {
            System.out.println(p);
        }
        oos.close();
        ois.close();
    }
}
